from flask import make_response, json


def success_json_result(data=None, msg='请求成功', code=200):
    json_data = {
        'success': True,
        'code': code,
        'msg': msg,
        'data': data
    }
    response = make_response(json.dumps(json_data, ensure_ascii=False))
    response.mimetype = "application/json"
    response.charset = "utf-8"
    return response


def fail_json_result(data=None, msg='请求失败', code=500):
    json_data = {
        'success': False,
        'code': code,
        'msg': msg,
        'data': data
    }
    response = make_response(json.dumps(json_data, ensure_ascii=False))
    response.mimetype = "application/json"
    response.charset = "utf-8"
    return response
